package Tree;

public class item110 {
}
class Solution110 {
    public boolean isBalanced(TreeNode root) {
        if(root == null)
            return true;

        if(Math.abs(helper(root.left) - helper(root.right)) > 1){
            return false;
        }
        boolean left = isBalanced(root.left);
        boolean right = isBalanced(root.right);
        return  left&& right;
    }

    public int helper(TreeNode node){
        if(node == null)
            return 0;

        int left = helper(node.left);
        int right = helper(node.right);

        return Math.max(left, right) + 1;
    }
}